<%
dim car
car = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0","1","2","3","4","5","6","7","8","9")

Sub ClaveProducto()
	if request.ServerVariables("SCRIPT_NAME") <> "/sn.asp" then	
		dim dbclave
		dbclave = ""
		Conectar_sol
		SQL = "SELECT Clave FROM Clave"
		Set Tabla = Conexion.Execute(SQL)
		if not tabla.eof then dbclave = tabla("Clave")
		Tabla.Close
		Desconectar
		
		if not ValidarClave(dbclave) then response.Redirect("/sn.asp")
	end if
End Sub

Function ValidarClave(clave)
		a = false
		if len(trim(clave)) > 0 then
			if trim(clave) = trim(DameClave(DameCodigo(DameSN))) then a = true
		end if
		ValidarClave = a
End Function	

Function DameSN()
	dim snd
	dim fso
	set fso = server.CreateObject("Scripting.FileSystemObject")
	set d = fso.getdrive(left(server.MapPath("/"),2))
	snd = cstr(not(d.SerialNumber))
	set d = nothing
	set fso = nothing
	DameSN = snd
End Function

Function DameClave(snv)
	isn = ""
	for i = 1 to len(snv)
		for j = 0 to ubound(car)
			if left(snv,1) = car(j) then isn = isn & cstr(j)
		next
		if len(snv) > 1 then snv = right(snv,len(snv)-1)
	next
	for i = 1 to len(isn)
		isnn = isnn & cstr(cint(left(isn,1)) + (i*6))
		if len(isn) > 1 then isn = right(isn,len(isn)-1)
	next
	DameClave = isnn
End Function

Function DameCodigo(isn)
	for i = 1 to len(isn)
		if cint(left(isn,2)) <= ubound(car) then
			snv = snv & car(cint(left(isn,2)))
			if len(isn) > 2 then isn = right(isn,len(isn)-2)
			i = i + 1
		else
			snv = snv & car(cint(left(isn,1)))
			if len(isn) > 1 then isn = right(isn,len(isn)-1)
		end if
	next
	DameCodigo = snv
End Function

%>